//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using System.Text;

namespace Rextester
{
    public class SimpleJSON
    {
        private static  bool NeedEscape(string src, int i)
        {
            char c = src[i];
            return c>127 || c == 47;
        }
        public static string EscapeString(string src)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int start = 0;
            for (int i = 0; i < src.Length; i++)
                if (NeedEscape(src, i))
                {
                //Console.WriteLine("escape "+src[i]);
                    sb.Append(src, start, i - start);
                    switch (src[i])
                    {
                        case '\b': sb.Append("\\b"); break;
                        case '\f': sb.Append("\\f"); break;
                        case '\n': sb.Append("\\n"); break;
                        case '\r': sb.Append("\\r"); break;
                        case '\t': sb.Append("\\t"); break;
                        case '\"': sb.Append("\\\""); break;
                        case '\\': sb.Append("\\\\"); break;
                        case '/': sb.Append("\\/"); break;
                        default:
                            sb.Append("\\u");
                            sb.Append(((int)src[i]).ToString("x04"));
                            break;
                    }
                    start = i + 1;
                }
            sb.Append(src, start, src.Length - start);
            return sb.ToString();
        }
    }
    public class Program
    {
        public static string CreateMD5(string input)
        {
            // Use input string to calculate MD5 hash
            using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
            {
                byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
                byte[] hashBytes = md5.ComputeHash(inputBytes);

                // Convert the byte array to hexadecimal string
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < hashBytes.Length; i++)
                {
                    sb.Append(hashBytes[i].ToString("X2"));
                }
                return sb.ToString();
            }
        }
        public static void Main(string[] args)
        {
            SortedDictionary<string, string> postdata = new SortedDictionary<string, string>();
            postdata["channel"]="1";
            postdata["domain"]="test.localhost.com";
            postdata["position"]="1";
            postdata["timestamp"]="15783932491";
            postdata["userHeadimg"]="http://localhost:8081/images/dp.png";
            postdata["userId"]="123310";
            postdata["userNickName"]="我叫哈哈哈123";
            postdata["userPhone"]="138132131";
            Console.WriteLine(JsonConvert.SerializeObject(postdata,Formatting.Indented));
            var jsonD = SimpleJSON.EscapeString(JsonConvert.SerializeObject(postdata));
            Console.WriteLine(jsonD);
            var md5 = CreateMD5(jsonD).ToLower();
            Console.WriteLine(md5);
            md5 = md5+"abc12313";
            Console.WriteLine(md5);
            Console.WriteLine(CreateMD5(md5).ToLower());
            
        }
    }
}